//
//  YYENoteCommentsViewController.m
//  YuYingEDU
//
//  Created by 胡波 on 2018/1/26.
//  Copyright © 2018年 胡波. All rights reserved.
//

#import "YYENoteCommentsViewController.h"
#import "UITextView+Placeholder.h"

@interface YYENoteCommentsViewController ()

@property (nonatomic,strong) UITextView *commentTV;

@end

@implementation YYENoteCommentsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    self.view.backgroundColor = GeneralBackColor;
    
    self.title = @"评论";
    
    [self configUI];
    
}

- (void)configUI {
    
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"发送" style:UIBarButtonItemStyleDone target:self action:@selector(sendClicked)];
    [self.navigationItem.rightBarButtonItem setTintColor:[UIColor blackColor]];
    
    UIView *contentView = [[UIView alloc]init];
    contentView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:contentView];
    
    self.commentTV = [[UITextView alloc]init];
    self.commentTV.placeholder = @"请输入评论";
    self.commentTV.placeholderLabel.textColor = LineColor;
    self.commentTV.placeholderLabel.font = [UIFont systemFontOfSize:15];
    self.commentTV.showsVerticalScrollIndicator = NO;
    self.commentTV.font = [UIFont systemFontOfSize:15];
    self.commentTV.textColor = [UIColor blackColor];
    [contentView addSubview:self.commentTV];
    
    [contentView makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.view.left).offset(8);
        make.right.equalTo(self.view.right).offset(-8);
        make.top.equalTo(self.view.top).offset(12);
        make.height.equalTo(SCREEN_WIDTH * 0.65);
    }];
    
    [self.commentTV makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(UIEdgeInsetsMake(11, 11, 11, 11));
    }];
    
}

// 发送
- (void)sendClicked {
    
    NSDictionary *dic = @{
                          @"uid":[LoginModel shareLogin].uid,
                          @"username":[LoginModel shareLogin].username,
                          @"token":[LoginModel shareLogin].token,
                          @"notes_id":self.noteID,
                          @"comment":self.commentTV.text
                          };
    [SVProgressHUD show];
    [AFNHelper post:AddNoteComment parameters:dic success:^(id responseObject) {
        
        NSLog(@"%@",responseObject);
        if ([responseObject[@"status"] isEqual:@1]) {
            
            if (self.block) {
                _block(1);
            }
            
            [self.navigationController popViewControllerAnimated:YES];
        }
        [SVProgressHUD showWithStatus:responseObject[@"message"]];
        [SVProgressHUD dismissWithDelay:0.5];
        
    } faliure:^(id error) {
        
        NSLog(@"请求失败");
        [SVProgressHUD showWithStatus:ShowError];
        [SVProgressHUD dismissWithDelay:0.5];
        
    }];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
